package com.ll.example.springbootwebdemokotlin.config

import com.ll.example.springbootwebdemokotlin.component.LoginHandlerInterceptor
import com.ll.example.springbootwebdemokotlin.component.MyLocaleResolver
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.LocaleResolver
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory
import org.springframework.boot.web.servlet.server.ServletWebServerFactory
import org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer






@Configuration
class MyMvcConfig : WebMvcConfigurer{
    /**
     * 设置首页跳转
     */
    override fun addViewControllers(registry: ViewControllerRegistry) {
       registry.addViewController("/").setViewName("login")
       registry.addViewController("/index.html").setViewName("login")
       registry.addViewController("/index").setViewName("login")

       registry.addViewController("/main.html").setViewName("dashboard")
    }

    /**
     * 注册拦截器
     */
    override fun addInterceptors(registry: InterceptorRegistry) {
       registry.addInterceptor(LoginHandlerInterceptor()).addPathPatterns("/**").
               excludePathPatterns("/index.html","/","/user/login","/index","/asserts/**")
    }

    @Bean
    fun localeResolver(): LocaleResolver {
        return MyLocaleResolver()
    }


}